package cn.kgc.waimai.service;

import cn.kgc.waimai.mapper.UserMapper;
import cn.kgc.waimai.pojo.User;
import cn.kgc.waimai.pojo.UserExample;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Scope
@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;


    @Override
    public User login(String number, String password) {
        UserExample userExample=new UserExample();
        UserExample.Criteria criteria=userExample.createCriteria();
        criteria.andNumberEqualTo(number);
        List<User> list=userMapper.selectByExample(userExample);
        System.out.println(list);
        User user=list.get(0);
        if (user==null){
            return null;
        }
        if(user.getPassword().equals(password)){
            return user;
        }
        return null;
    }
}